/*
** windalert AjaxLoader
*/

var AjaxLoaderPlugin = {
    objectName: false,
    actionUrl: false,
    var1: false,
    var2: false,
    init: function (objectName, actionUrl, var1, var2) {
        this.objectName = objectName;
        this.actionUrl = actionUrl;
        this.var1 = var1;
        this.var2 = var2;
    },
    action: function () {
        var targetDiv = $('#' + this.objectName);
        var targetPleaseWaitDiv = $('#' + this.objectName + '-please-wait');
        targetPleaseWaitDiv.show();
        $.ajax({
            cache: false,
            url: this.actionUrl,
            data: { "var1": this.var1, "var2": this.var2},
            type: 'post',
            success: function (data) {
                if (data.error) {
                    targetDiv.html(data.error);
                }
                if (data.html) {
                    targetPleaseWaitDiv.hide();
                    targetDiv.replaceWith(data.html);
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert('Failed.');
            }
        });
    },
};